package dao

import (
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

var DB *gorm.DB

func InitMysql() (err error) {
	// 连接数据库
	dsn := "root:Wlh19970501@tcp(localhost:3306)/go_db?charset=utf8&parseTime=True&loc=Local"
	DB, err = gorm.Open("mysql", dsn)
	if err != nil {
		fmt.Println("connect mysql err:", err)
		return
	}
	return DB.DB().Ping()
}

func Close() {
	DB.Close()
}
